Task References

On this page:

slice (string)

Purpose

Similar to the substring task, the string slice task extracts part of a provided string and returns the extracted part in a new string. The part of the string you want to extract is specified between the start and end indexes, or to the end of the string.

Potential Use Case

If you need to extract only the telephone area code from an incoming string, using slice would provide the means by which to accomplish this.

Properties

Input and output properties are shown below.

Incoming Type Description
str String Required. The string that contains the value to be extracted.
beginIndex Number Required. The position in the string to begin the extraction. The first character in the string has position 0, the second has position 1, and so on. Numbering starts (and defaults) at position '0' (the beginning of the str value).
endIndex Number Optional. The position in the string to stop the extraction. Numbering also begins from the start of the string and represents the point up to, but not including, where slicedString should end the extraction.

Note: If the value of endIndex is less than the value of beginIndex, the output value of slicedString will return an empty string (""). If this is not the behavior that is desired, then consider using the substring Task Reference.


Outgoing Type Description
slicedString String The extracted value in str that is specified by the beginIndex and endIndex parameters.

Examples

Example 1

In the IAP example shown below:

  • The str variable has been statically set as 800-555-1212.

  • The beginIndex variable has been set to 7, indicating the extraction should begin at the second dash in the str value.

  • The endIndex variable has been set to 4, indicating the extraction should only proceed up until (but not including) character 4. Remember, character numbering starts at '0', so character 4 in this case is the first number "5" character.

  • Because the beginIndex value is greater than the endIndex value, the slicedString output variable will have the value of "" (an empty string).

    substring1

Example 2

In the IAP example shown below:

  • The str variable has been statically set as 800-555-1212.

  • The beginIndex variable has been set to 4, indicating the extraction should begin at position number 4 of the str value.

  • The endIndex variable has been set to 7, indicating the extraction should only proceed up until (but not including) character 7. Remember, numbering starts at '0', so character 7 in this case is the second "-" character.

  • The slicedString output variable will have the value of 555.

    substring2